package lol.clann.minecraft.exampleplugin;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 插件包路径下,被@Service注解的类,会作为一个单例bean,交给spring进行管理
 *
 * SBP会自动注册监听器
 *
 * @author pyz
 * @date 2019/5/12 12:33 PM
 */
@Service
public class ExampleEventListener implements Listener {
    //   记录日志
    private static Logger LOGGER = LoggerFactory.getLogger(ExampleEventListener.class);
    //  spring会自把需要的对象注入进来
    @Autowired
    private ExampleConfig exampleConfig;

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEvent(PlayerQuitEvent event) {
        LOGGER.info(exampleConfig.getQuitMessage(), event.getPlayer().getName());
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEvent(PlayerJoinEvent event) {
        LOGGER.info(exampleConfig.getHelloMessage(), event.getPlayer().getName());
    }
}
